import { fetch } from "../adapter";
import { Requester } from "..";

// 可以被替换的 请求器
export const fetchRequester: Requester = async (url, method, headers, body) => {
    return fetch(url.toString(), {
        method,
        headers,
        body,
    }).then(async (res) => {
        const tag = globalThis.window === globalThis;
        const { status, headers } = res;
        if (tag) {
            const body = await res.blob();
            return {
                status,
                headers,
                data: { type: "binary", body },
            };
        } else {
            const body = await res.arrayBuffer();
            return {
                status,
                headers,
                data: { type: "arrayBuffer", body },
            };
        }
    });
};
